using System.Collections.Generic;
using OneSignalPush.MiniJSON;
using UnityEngine;

public class OneSignal : MonoBehaviour
{
	public enum LOG_LEVEL
	{
		NONE = 0,
		FATAL = 1,
		ERROR = 2,
		WARN = 3,
		INFO = 4,
		DEBUG = 5,
		VERBOSE = 6
	}

	public delegate void NotificationReceived(string message, Dictionary<string, object> additionalData, bool isActive);

	public delegate void IdsAvailable(string playerID, string pushToken);

	public delegate void TagsReceived(Dictionary<string, object> tags);

	private const string gameObjectName = "OneSignalRuntimeObject_KEEP";

	public static IdsAvailable idsAvailableDelegate;

	public static TagsReceived tagsReceivedDelegate;

	private static LOG_LEVEL logLevel = LOG_LEVEL.INFO;

	private static LOG_LEVEL visualLogLevel;

	private static OneSignalPlatform oneSignalPlatform;

	private static bool initialized;

	internal static NotificationReceived notificationDelegate;

	public static void Init(string appId, string googleProjectNumber, NotificationReceived inNotificationDelegate, bool autoRegister)
	{
		if (!initialized)
		{
			oneSignalPlatform = new OneSignalAndroid("OneSignalRuntimeObject_KEEP", googleProjectNumber, appId, logLevel, visualLogLevel);
			notificationDelegate = inNotificationDelegate;
			GameObject gameObject = new GameObject("OneSignalRuntimeObject_KEEP");
			gameObject.AddComponent<OneSignal>();
			Object.DontDestroyOnLoad(gameObject);
			initialized = true;
		}
	}

	public static void Init(string appId, string googleProjectNumber, NotificationReceived inNotificationDelegate)
	{
		Init(appId, googleProjectNumber, inNotificationDelegate, true);
	}

	public static void Init(string appId, string googleProjectNumber)
	{
		Init(appId, googleProjectNumber, null, true);
	}

	public static void Init(string appId)
	{
		Init(appId, null, null, true);
	}

	public static void SetLogLevel(LOG_LEVEL inLogLevel, LOG_LEVEL inVisualLevel)
	{
		logLevel = inLogLevel;
		visualLogLevel = inVisualLevel;
	}

	public static void SendTag(string tagName, string tagValue)
	{
		oneSignalPlatform.SendTag(tagName, tagValue);
	}

	public static void SendTags(IDictionary<string, string> tags)
	{
		oneSignalPlatform.SendTags(tags);
	}

	public static void GetTags(TagsReceived inTagsReceivedDelegate)
	{
		tagsReceivedDelegate = inTagsReceivedDelegate;
		oneSignalPlatform.GetTags();
	}

	public static void GetTags()
	{
		oneSignalPlatform.GetTags();
	}

	public static void DeleteTag(string key)
	{
		oneSignalPlatform.DeleteTag(key);
	}

	public static void DeleteTags(IList<string> keys)
	{
		oneSignalPlatform.DeleteTags(keys);
	}

	public static void SendPurchase(double amount)
	{
	}

	public static void RegisterForPushNotifications()
	{
		oneSignalPlatform.RegisterForPushNotifications();
	}

	public static void GetIdsAvailable(IdsAvailable inIdsAvailableDelegate)
	{
		idsAvailableDelegate = inIdsAvailableDelegate;
		oneSignalPlatform.IdsAvailable();
	}

	public static void GetIdsAvailable()
	{
		oneSignalPlatform.IdsAvailable();
	}

	public static void EnableVibrate(bool enable)
	{
		((OneSignalAndroid)oneSignalPlatform).EnableVibrate(enable);
	}

	public static void EnableSound(bool enable)
	{
		((OneSignalAndroid)oneSignalPlatform).EnableSound(enable);
	}

	private void onPushNotificationReceived(string jsonString)
	{
		if (notificationDelegate != null)
		{
			oneSignalPlatform.FireNotificationReceivedEvent(jsonString, notificationDelegate);
		}
	}

	private void onIdsAvailable(string jsonString)
	{
		if (idsAvailableDelegate != null)
		{
			Dictionary<string, object> dictionary = Json.Deserialize(jsonString) as Dictionary<string, object>;
			idsAvailableDelegate((string)dictionary["userId"], (string)dictionary["pushToken"]);
		}
	}

	private void onTagsReceived(string jsonString)
	{
		tagsReceivedDelegate(Json.Deserialize(jsonString) as Dictionary<string, object>);
	}

	private void OnApplicationPause(bool paused)
	{
		oneSignalPlatform.OnApplicationPause(paused);
	}
}
